package cn.edu.hnit.javaee.experiments.experiment01;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import cn.edu.hnit.javaee.experiments.experiment01.dao.StudentDao;
import cn.edu.hnit.javaee.experiments.experiment01.model.StudentPOJO;
import cn.edu.hnit.javaee.experiments.experiment01.service.StudentServiceImpl;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
    	String resource = "mybatis-config.xml";
		try {
			InputStream inputStream = Resources.getResourceAsStream(resource);
			SqlSessionFactory sqlSessionFactory = 
					new SqlSessionFactoryBuilder().build(inputStream);
			SqlSession sqlSession = sqlSessionFactory.openSession(true);
			StudentDao studentDao = sqlSession.getMapper(StudentDao.class);
			StudentServiceImpl studentServiceImpl = new StudentServiceImpl();
			studentServiceImpl.setStudentDao(studentDao);
			 StudentPOJO studentPOJO = new StudentPOJO();
				studentPOJO.setName("一");
			System.out.println(studentServiceImpl.getPage(1, studentPOJO).size());
		} catch(IOException e) {
			e.printStackTrace();
		}
    }
}
